package com.git.dengchongshuang.managementsystem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;

//显示通讯录中的联系人
public class View {

    static void showContactByName(String name) {
        List<Contact> contacts = OperateContacts.getContactByName(name);
        showContactList(contacts);

    }


    static void showAllContactOrderByAddTime(boolean isUp) {
        ArrayList<Contact> contacts = OperateContacts.getAllContact();
        if (isUp) {
            showContactList(contacts);
        } else{
            reverseContactList(contacts);
            showContactList(contacts);
        }
    }

    static void showAllContactOrderByName(boolean isUp) {
        List<Contact> contacts = OperateContacts.getAllContactOrderByName();
        if (isUp) {
            showContactList(contacts);
        } else{
            reverseContactList(contacts);
            showContactList(contacts);
        }

    }


    static void showAllContactOrderByPhoneNumber(boolean isUp) {
        List<Contact> contacts = OperateContacts.getAllContactOrderByPhoneNumber();
        if (isUp) {
            showContactList(contacts);
        } else{
            reverseContactList(contacts);
            showContactList(contacts);
        }
    }

    static void showContact(Contact contact) {
        System.out.println("******************************");
        System.out.println("姓名：" + contact.getName());
        System.out.println("电话：" + contact.getPhoneNumber());
        System.out.println("邮件：" + contact.getEmail());
        System.out.println("工作：" + contact.getJob());
        System.out.println("公司：" + contact.getCompany());
        System.out.println("******************************\n");
    }

    /**
     * 显示联系人列表
     * @param contacts 需要显示的联系人
     */
    public static void showContactList(List<Contact> contacts) {
        System.out.println("姓名\t电话\t\t邮件\t\t工作\t\t公司");
        for (Contact c : contacts) {
            System.out.println(c.getName() + "\t" + c.getPhoneNumber()
                    + "\t" + c.getEmail() + "\t" + c.getJob()
                    + "\t" + c.getCompany());
        }
    }

    public static void reverseContactList(List<Contact> contacts) {
        Collections.reverse(contacts);
    }

    static void desc(ArrayList<Contact> contacts) {
        Collections.reverse(contacts);
        for (Contact c : contacts) {
            showContact(c);
        }
    }
}
